package com.zhongkai.controller;

import com.zhongkai.app.service.RoleSetService;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 角色管理
 * */
@Controller
public class RoleSetController {

    @Autowired
    private RoleSetService roleSetService;

    /**
     * 角色添加
     *
     * @param role_name   角色名称
     * @param number_list 角色权限(1,1,1,1)
     */
    @RequestMapping(value = "/section/add", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addSection(String role_name, String number_list) {

        ZhongkaiResult result = roleSetService.addRoleSet(role_name,number_list);

        return result;
    }



    /**
     * 导航栏列表
     */
    @RequestMapping(value = "/section/menus_list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult getMenusList() {

        ZhongkaiResult result = roleSetService.getMenusList();

        return result;
    }


    /**
     * 角色修改
     * @param role_id   角色id
     * @param number_list 角色权限(1,1,1,1)
     */
    @RequestMapping(value = "/section/update", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateRoleSet(@RequestParam(defaultValue = "0")Integer role_id, String number_list) {

        ZhongkaiResult result = roleSetService.updateRoleSet(role_id,number_list);

        return result;
    }


    /**
     * 角色删除
     * @param role_id   角色id
     */
    @RequestMapping(value = "/section/remove", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeRoleSet(@RequestParam(defaultValue = "0")Integer role_id) {

        ZhongkaiResult result = roleSetService.removeRoleSet(role_id);

        return result;
    }



    /**
     * 角色列表
     *
     * @param page 页数
     * @param rows 每页数据条数
     */
    @RequestMapping(value = "/section/role_list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listRoleSet(@RequestParam(defaultValue = "0")Integer page, @RequestParam(defaultValue = "0")Integer rows) {

        ZhongkaiResult result = roleSetService.listRoleSet(page,rows);

        return result;
    }
}
